﻿# hello world.py
print "Hello World"



# try 异常处理
try:
    f = open(r'py.txt')
    print f.read()
finally:
    if f:
        f.close()
print "-----------------"

# with 省略   用with 代替 try……finally
with open(r'py.txt','r') as fileReader:
        print fileReader.read()

print "-----------------"
# 对上面代码进行优化
with open(r'py.txt','r') as fileReaderlines:
    for line in fileReaderlines.readlines():
        print line.strip()
print "-----------------"


#写文件
wf = open('1.txt','w')
wf.write('123456789')
wf.close()

